#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#include <math.h>
#include <stdio.h>
#include <unistd.h>//sleep$B4X?tMQ(B


int main()
{
    ALCdevice *device;
    ALCcontext *context;
    ALshort data[22050];
    ALuint buffer, source;
    int i;

    device = alcOpenDevice(NULL);
    context = alcCreateContext(device, NULL);
    alcMakeContextCurrent(context);
    alGenBuffers(1, &buffer);

    for (i = 0; i < 22050; ++i) {
        data[i] = sin(i * 3.14159 * 2 * 440 / 22050) * 32767;
    }

    alBufferData(buffer, AL_FORMAT_MONO16, data, sizeof(data), 22050);
    alGenSources(1, &source);
    alSourcei(source, AL_BUFFER, buffer);
    alSourcePlay(source);
    sleep(1);
    alSourceStop(source);
    alDeleteSources(1, &source);
    alDeleteBuffers(1, &buffer);
    alcMakeContextCurrent(NULL);
    alcDestroyContext(context);
    alcCloseDevice(device);
    return 0;
}
